package system.shoeHouse.interceptor;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
@SuppressWarnings({ "unchecked", "rawtypes" })
public class BackInterceptor implements HandlerInterceptor{
	private List<String> uncheckUrls; 
	
	public List<String> getUncheckUrls() {
		return uncheckUrls;
	}

	public void setUncheckUrls(List<String> uncheckUrls) {
		this.uncheckUrls = uncheckUrls;
	}

	@Override
	public void afterCompletion(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, Exception arg3)
			throws Exception {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void postHandle(HttpServletRequest request, HttpServletResponse response, Object arg2, ModelAndView arg3)
			throws Exception {
		// TODO Auto-generated method stub
		
		
	}

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object arg2) throws Exception {
		// TODO Auto-generated method stub
		String requestUrl = request.getRequestURI(); 
		if(uncheckUrls.contains(requestUrl)){ 
		return true; 
		}else{ 
			HttpSession session = request.getSession();
			System.out.println("yyyyyyyyyyyyyyyy");
			if(session.getAttribute("userInfo")==null){
				response.sendRedirect("/shoeHouse/webApp/login.jsp");
				
				return false;
			}else{
				return true; 
			}
			
		//TODO 做拦截的事情 
		}
		
		
		
		
	
	}

}
